<?php
namespace app\shop\model;

use think\Db;

class ClientCategory extends \ShopModel
{
    protected $table = 'sh_client_category_relevance';

    public function ClientCategoryDb(){
        return Db::name('client_category_relevance');
    }

    //列表
    public function categoryList($params){
        $where = [];
        if(!empty($params['query'])){
            $where['client_cate_name'] = ['like','%'.$params['query'].'%'];
        }
        
        $data =  Db::name('client_category')->where($where)->field('client_cate_id,client_cate_name')->select();
        foreach($data as &$v){
            $v['is_checked'] = false;
        }
        return $data;
    }

    //添加分类
    public function add($params){
        Db::name('client_category')->insert($params);
        return true;
    }

    //分类重命名
    public function rename($params){
        Db::name('client_category')->where('client_cate_id',$params['client_cate_id'])->update(['client_cate_name'=>$params['client_cate_name']]);
        return true;
    }

    //删除分类
    public function del_cate($id){
        Db::name('client_category')->where('client_cate_id',$id)->delete();
    }

}